{extend name="$BASE_LIST" /}
{block name="body"}
<link rel="stylesheet" type="text/css" href="__STATIC__/monthPicker/dateRange.css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/monthPicker/monthPicker.css"/>

<div class="right-main">
    <div class="page_nav" id="js_page_nav"><span class="page_title">{$page_nav}</span></div>
    <div id="js_main_header" class="ui-form main_header">
        <div class="left margin-right-5">
            <input style="width:200px" class="form-control" id="month_picker" size="20"/>
        </div>
        <span class="frm_input_box search append">
            <a href="javascript:void(0);" id="js_search" class="frm_input_append">
                <i class="icon wb-search" title="搜索"></i>
            </a>
            <input type="text" id="js_keyword" placeholder="请输入视频标题" value="" class="frm_input"/>
        </span>
    </div>
    <table id="grid-table">
        <thead frozen="true">
        <th data-options="field:'phone',width:140,align:'center'">用户</th>
        <th data-options="field:'video_title',width:140,align:'center'">视频标题</th>
        <th data-options="field:'video_img',width:100,align:'center',formatter:formatImg">视频封面</th>
        <th data-options="field:'video_path',width:100,align:'center',formatter:formatVideo">视频地址</th>
        <th data-options="field:'is_dispose',width:100,align:'center',formatter:formatIsDispose">是否已处理</th>
        </thead>
        <thead>
        <tr>
            <th data-options="field:'content',width:500, align:'center'">举报内容</th>
            <th data-options="field:'create_time',width:150, align:'center'">创建时间</th>
            <th data-options="field:'update_time',width:150, align:'center'">更新时间</th>
            <th data-options="field:'_oper',halign:'center',formatter: formatOper">操作</th>
        </tr>
        </thead>
    </table>
</div>

{/block}
{block name="script"}
<script type="text/javascript" src="__STATIC__/monthPicker/dateRange.js"></script>
<script type="text/javascript" src="__STATIC__/monthPicker/monthPicker.js"></script>
<script type="text/javascript">
    var myDate = new Date();
    var month = parseInt(myDate.getMonth()) + 1;
    var toDay = myDate.getFullYear() + '-' + month + '-' + myDate.getDate();
    var dateRange = new pickerDateRange('month_picker', {
        startDate: '2000-01-01',
        endDate: toDay,
        defaultText: ' 至 ',
        theme: 'ta'
    });
    function formatImg(value, row, index) {
        html = '';
        if(value!=null){
            html = '<a href="'+value+'" target="_blank"><img src="'+value+'" style="max-width:50px;max-height:20px;text-align: center"></a>';
        }
        return html;
    }

    function formatVideo(value, row, index) {
        html = '';
        if(value!=null){
            html = '<video src="'+value+'" style="max-width:50px;max-height:20px;text-align: center" onclick="openVideo(\''+value+'\')"></video>';
        }
        return html;
    }

    function openVideo(path){
        var url = getURL('play')+'?path='+path;
        openBarWin('播放视频', 1000, 600, url, function () {
            reload();
        });
    }
    function formatIsDispose(value,row,index){
        var text = '<span style="color:green">否</span>';
        if(value == 1){
            text = '<span style="color:red">是</span>';
        }
        return text;
    }
    function formatOper(value, row, index) {
        var html = '<span class="grid-operation">';
        if(row['is_dispose'] == 0){
            html += '<button type="button" onclick="del(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>下架</button>';
            html += '<button type="button" onclick="rejected(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>封号</button>';
        }
        html += '</span>';
        return html;
    }

    $(function () {
        $('#grid-table').datagrid({
            url: getURL('loadList'),
            method: "GET",
            height: getGridHeight(),
            rownumbers: true,
            singleSelect: true,
            remoteSort: false,
            multiSort: true,
            emptyMsg: '<span>无相关数据</span>',
            pagination: true,
            pageSize: 20,
            showFooter:true,
            onLoadSuccess: function(data){
            }
        });
        //设置分页控件
        $('#grid-table').datagrid('getPager').pagination({
            pageSize: 20, //每页显示的记录条数，默认为10
            pageList: [20, 30, 50]
        });
    });



    function del(id) {
        var url = getURL('del', 'id=' + id);
        openBarWin('删除', 600, 200, url, function () {
            reload();
        }, ['确定','取消']);
    }

    function rejected(id) {
        var url = getURL('rejected', 'id=' + id);
        openBarWin('驳回', 600, 200, url, function () {
            reload();
        }, ['确定','取消']);
    }

    $("#js_search").click(function () {
        reload();
    });

    function reload() {
        var keyword = $("#js_keyword").val();
        var month_picker = $("#month_picker").val();
        var arr = month_picker.split(" 至 ");
        var startDate = arr[0];
        var endDate = arr[1];
        $('#grid-table').datagrid('reload', {
            keyword: keyword,
            startDate: startDate,
            endDate: endDate
        });
    }


</script>
{/block}